//
//  LogViewController.m
//  MyChatchat
//
//  Created by 小灰灰的pro on 16/3/30.
//  Copyright © 2016年 小灰灰. All rights reserved.
//

#import "LogViewController.h"
#import <CDChatManager.h>
#import "ChatViewController.h"
@interface LogViewController ()
@property (nonatomic,strong)UITextField *idTextField;
@property (nonatomic,strong)UIButton *loginButton;
@end

@implementation LogViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initLayout];
}
- (void)initLayout{
    self.idTextField = [[UITextField alloc] initWithFrame:CGRectMake(50, 220, [UIScreen mainScreen].bounds.size.width - 100, 30)];
    self.idTextField.borderStyle = UITextBorderStyleRoundedRect;
    [self.view addSubview:self.idTextField];
    self.loginButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.loginButton.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - 100) / 2, 420, 100, 30);
    [self.loginButton setTitle:@"登录" forState:UIControlStateNormal];
    [self.loginButton addTarget:self action:@selector(loginButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.loginButton];
}

- (void)loginButtonAction{
//    //开启客户端之前关闭之前的客户端(有问题,加上之后登陆界面就不跳转)
//    [[CDChatManager manager]closeWithCallback:^(BOOL succeeded, NSError *error) {
    //开启客户端
    [[CDChatManager manager]openWithClientId:self.idTextField.text callback:^(BOOL succeeded, NSError *error) {
        ChatViewController *chatVC = [ChatViewController new];
        [self.navigationController pushViewController:chatVC animated:YES];
    }];
//    }];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.idTextField resignFirstResponder];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
